package com.edu.exam.entity.assessment.technical;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 相似度结果实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：similarity_result
 *
 * 根据B-02-06试题查重子模块设计文档实现
 * 管理试题相似度分析结果，支持多种相似度计算算法和详细分析。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "similarity_result")
@Comment("相似度结果表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SimilarityResult {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 相似度结果唯一标识符
     */
    @NotBlank(message = "相似度结果ID不能为空")
    @Size(max = 50, message = "相似度结果ID长度不能超过50个字符")
    @Column(name = "result_id", nullable = false, length = 50, unique = true)
    private String resultId;

    /**
     * 查重记录ID（外键关联到question_check_records）
     */
    @NotBlank(message = "查重记录ID不能为空")
    @Size(max = 50, message = "查重记录ID长度不能超过50个字符")
    @Column(name = "record_id", nullable = false, length = 50)
    private String recordId;

    /**
     * 源试题ID
     */
    @NotNull(message = "源试题ID不能为空")
    @Column(name = "source_question_id", nullable = false)
    private Long sourceQuestionId;

    /**
     * 目标试题ID
     */
    @NotNull(message = "目标试题ID不能为空")
    @Column(name = "target_question_id", nullable = false)
    private Long targetQuestionId;

    /**
     * 算法类型（TEXT-文本相似度，SEMANTIC-语义相似度，STRUCTURE-结构相似度）
     */
    @NotBlank(message = "算法类型不能为空")
    @Size(max = 20, message = "算法类型长度不能超过20个字符")
    @Column(name = "algorithm_type", nullable = false, length = 20)
    private String algorithmType;

    /**
     * 相似度得分（0-1之间）
     */
    @NotNull(message = "相似度得分不能为空")
    @Column(name = "similarity_score", nullable = false, precision = 5, scale = 4)
    private BigDecimal similarityScore;

    /**
     * 相似度等级（HIGH-高度相似，MEDIUM-中度相似，LOW-低度相似，NONE-无相似）
     */
    @Size(max = 20, message = "相似度等级长度不能超过20个字符")
    @Column(name = "similarity_level", length = 20)
    private String similarityLevel;

    /**
     * 置信度（0-1之间）
     */
    @Column(name = "confidence_score", precision = 5, scale = 4)
    private BigDecimal confidenceScore;

    /**
     * 匹配特征数量
     */
    @Column(name = "matched_features")
    private Integer matchedFeatures;

    /**
     * 总特征数量
     */
    @Column(name = "total_features")
    private Integer totalFeatures;

    /**
     * 匹配关键词数量
     */
    @Column(name = "matched_keywords")
    private Integer matchedKeywords;

    /**
     * 总关键词数量
     */
    @Column(name = "total_keywords")
    private Integer totalKeywords;

    /**
     * 匹配句子数量
     */
    @Column(name = "matched_sentences")
    private Integer matchedSentences;

    /**
     * 总句子数量
     */
    @Column(name = "total_sentences")
    private Integer totalSentences;

    /**
     * 结构相似度得分（用于结构相似度算法）
     */
    @Column(name = "structure_similarity", precision = 5, scale = 4)
    private BigDecimal structureSimilarity;

    /**
     * 语义相似度得分（用于语义相似度算法）
     */
    @Column(name = "semantic_similarity", precision = 5, scale = 4)
    private BigDecimal semanticSimilarity;

    /**
     * 文本相似度得分（用于文本相似度算法）
     */
    @Column(name = "text_similarity", precision = 5, scale = 4)
    private BigDecimal textSimilarity;

    /**
     * 相似度详情（JSON格式，存储详细的匹配信息）
     */
    @Column(name = "similarity_details", columnDefinition = "TEXT")
    private String similarityDetails;

    /**
     * 匹配段落列表（JSON格式）
     */
    @Column(name = "matched_paragraphs", columnDefinition = "TEXT")
    private String matchedParagraphs;

    /**
     * 匹配关键词列表（JSON格式）
     */
    @Column(name = "matched_keyword_list", columnDefinition = "TEXT")
    private String matchedKeywordList;

    /**
     * 差异分析结果（JSON格式）
     */
    @Column(name = "difference_analysis", columnDefinition = "TEXT")
    private String differenceAnalysis;

    /**
     * 算法参数（JSON格式，记录算法运行时使用的参数）
     */
    @Column(name = "algorithm_params", columnDefinition = "TEXT")
    private String algorithmParams;

    /**
     * 算法版本
     */
    @Size(max = 20, message = "算法版本长度不能超过20个字符")
    @Column(name = "algorithm_version", length = 20)
    private String algorithmVersion;

    /**
     * 计算耗时（毫秒）
     */
    @Column(name = "calculation_duration")
    private Long calculationDuration;

    /**
     * 是否推荐为相似试题
     */
    @Column(name = "is_recommended")
    private Boolean isRecommended;

    /**
     * 推荐理由
     */
    @Size(max = 500, message = "推荐理由长度不能超过500个字符")
    @Column(name = "recommendation_reason", length = 500)
    private String recommendationReason;

    /**
     * 人工审核结果
     */
    @Size(max = 20, message = "人工审核结果长度不能超过20个字符")
    @Column(name = "manual_review_result", length = 20)
    private String manualReviewResult;

    /**
     * 人工审核意见
     */
    @Size(max = 1000, message = "人工审核意见长度不能超过1000个字符")
    @Column(name = "manual_review_comment", columnDefinition = "TEXT")
    private String manualReviewComment;

    /**
     * 人工审核时间
     */
    @Column(name = "manual_review_time")
    private LocalDateTime manualReviewTime;

    /**
     * 人工审核人员ID
     */
    @Size(max = 50, message = "人工审核人员ID长度不能超过50个字符")
    @Column(name = "manual_reviewer_id", length = 50)
    private String manualReviewerId;

    /**
     * 人工审核人员姓名
     */
    @Size(max = 100, message = "人工审核人员姓名长度不能超过100个字符")
    @Column(name = "manual_reviewer_name", length = 100)
    private String manualReviewerName;

    /**
     * 是否为最佳匹配
     */
    @Column(name = "is_best_match")
    private Boolean isBestMatch;

    /**
     * 排序权重（用于排序相似结果）
     */
    @Column(name = "sort_weight")
    private Integer sortWeight;

    /**
     * 创建者ID
     */
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;
}